﻿#ifndef CONTROLACTIONWIDGET_H
#define CONTROLACTIONWIDGET_H

#include <QWidget>
#include "items/outctrlitem.h"
#include "mybutton.h"
#include "setcontrolstyle.h"
#include <QMouseEvent>
#include <QDateTime>
#include "mctype/mainwidgetfunction.h"

#include <QTimer>

#define BORDER_RADIUS "5"

namespace Ui {
class ControlActionWidget;
}

class ControlActionWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ControlActionWidget(QWidget *parent = 0);
    ~ControlActionWidget();

private:
    Ui::ControlActionWidget *ui;

    enum BTNEVENT { BTNCLICK = 1, BTNPRE, BTNREL};

    int m_itemPerPage;//界面每页条目数
    int m_btnPerRow;//每行按钮数
    int m_curPage;//当前页数
    QList<QFrame*> m_itemFrameList;
    QList<QLabel*> m_itemLabelList;
    QList<MyButton*> m_itemBtnList;
    QList <OutCtrlItem> m_allItemList;
    QList <OutCtrlItem> m_itemList;

    QTimer * m_motorTimer;  // 电机停止命令多次发送
    int m_speed;//换挡速度

private:
    void initControl();//初始化窗体控件，包括位置、尺寸、样式
    void initResolution();
    void initControlStyle();//初始化窗体控件样式

    void btnAction(int rowidx, int btnidx, int event);//按钮动作，参数包括行、按钮索引、按钮事件
    void excuteOrder(int def,int fun);//执行按钮动作

public:
    void setTypeLogo(QString tStyle);//设置类型图标
    void setMainTitle(QString str);//设置主title
    void setSubTitle(QString str);//设置副title
    void setdefName(int def,int value);

    void refreshUi(int idx = 0);

public:
    void addItemList(QList<OutCtrlItem> itemList);

private slots:
    void slotItemBtnClicked();//控制按钮被点击
    void slotItemBtnPressed();//控制按钮按下
    void slotItemBtnReleased();//控制按钮抬起
    void on_buttonPgUp_clicked();
    void on_buttonPgDn_clicked();
    void on_buttonBack_clicked();

public slots:
    void slotSpeed(int speed);
 //鼠标事件
protected:
    void mousePressEvent(QMouseEvent *e);
    void mouseReleaseEvent(QMouseEvent *e);

private:
    int m_mousePressX;
    int m_mousePressY;
    int m_mouseReleaseX;
    int m_mouseReleaseY;

};

#endif // CONTROLACTIONWIDGET_H
